package com.cgnpc.scp.run.controller;

import com.cgnpc.cud.annotation.OperatorType;
import com.cgnpc.cud.annotation.UBA;
import com.cgnpc.cud.core.controller.BaseController;
import com.cgnpc.cud.core.domain.AjaxResult;
import com.cgnpc.scp.achievement.pojo.IdReq;
import com.cgnpc.scp.common.bean.CreateFileInfo;
import com.cgnpc.scp.common.bean.MyPageResult;
import com.cgnpc.scp.common.utils.AjaxResultUtil;
import com.cgnpc.scp.run.mybatis.entity.MarketInfo;
import com.cgnpc.scp.run.pojo.MarketInfoVo;
import com.cgnpc.scp.run.service.MarketInfoService;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**********************************
 * 用途说明: 市场机会
 * 作者姓名: zhangyibing
 * 创建时间: 2020年9月13日15:46:40
 ***********************************/
@RestController
@RequestMapping("/run/marketInfo")
public class MarketInfoController extends BaseController {
    private static final Logger LOGGER = LoggerFactory.getLogger(MarketInfoController.class);

    @Autowired
    private MessageSource messageSource;

    @Autowired
    private MarketInfoService marketInfoService;

    /**********************************
     * 用途说明: 查询市场机会 列表
     * 参数说明 marketInfo 查询实体
     * 返回值说明: 市场机会列表
     ***********************************/
    @ApiOperation(value="查询市场机会 列表")
    @UBA(module = "调试经营管理", action = "市场机会分页查询", channel = OperatorType.Page)
    @RequestMapping(value = "/listPage", method = {RequestMethod.POST})
    public AjaxResult listPage(HttpServletRequest request, @RequestBody MarketInfo marketInfo) {
        try {
            MyPageResult<MarketInfo> result = marketInfoService.queryMarketInfoPageList(marketInfo);
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,result);
        } catch (Exception e) {
            LOGGER.error("MarketInfoController listPage error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 查询市场机会 详细信息
     * 参数说明 req id
     * 返回值说明: 市场机会详情
     ***********************************/
    @ApiOperation(value="查询市场机会详情信息")
    @UBA(module = "调试经营管理", action = "查看市场机会详情", channel = OperatorType.Button)
    @RequestMapping(value = "/getMarketInfoById", method = {RequestMethod.POST})
    public AjaxResult getMarketInfoById(HttpServletRequest request, @RequestBody IdReq req){
        try {
            MarketInfoVo result = marketInfoService.getMarketInfoById(req.getId());
            if (result != null)
                return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,result);
            else
                return AjaxResultUtil.createI18nDefaultError(request,messageSource,"查询失败，没有找到对应记录!");
        } catch (Exception e) {
            LOGGER.error("MarketInfoController getMarketInfoById error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 调试经营管理-市场机会-导出Excel
     * 参数说明: HttpServletRequest request, @RequestBody T reqEntity
     * 返回值说明: Object
     ***********************************/
    @ApiOperation(value = "调试经营管理-市场机会-导出Excel")
    @UBA(module = "调试经营管理", action = "市场机会导出 Excel", channel = OperatorType.Button)
    @RequestMapping(value = "/exportExcel", method = {RequestMethod.POST})
    @ResponseBody
    public <T extends MarketInfo> Object exportExcel(HttpServletRequest request, @RequestBody T reqEntity) {
        try {
            CreateFileInfo createFileInfo = marketInfoService.exportExcel(reqEntity);
           return AjaxResultUtil.createSuccessMessage(createFileInfo);
        } catch (Exception e) {
            LOGGER.error("MarketInfoController exportExcel error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }

    }

    /**********************************
     * 用途说明: 同心圆取号
     * 参数说明: HttpServletRequest request, @RequestBody T reqEntity
     * 返回值说明: Object
     ***********************************/
    @ApiOperation(value = "同心圆取号")
    @UBA(module = "调试经营管理", action = "同心圆区号", channel = OperatorType.Button)
    @RequestMapping(value = "/offerNumber", method = {RequestMethod.POST})
    @ResponseBody
    public  AjaxResult offerNumber(HttpServletRequest request, @RequestBody Map<String, Object> param) {
        try {
            return marketInfoService.offerNumber(param);
        } catch (Exception e) {
            LOGGER.error("MarketInfoController offerNumber error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 获取市场机会数据
     * 参数说明: HttpServletRequest request, @RequestBody T reqEntity
     * 返回值说明: Object
     ***********************************/
    @ApiOperation(value = "获取市场机会数据")
    @RequestMapping(value = "/getMarketInfoByTimer", method = {RequestMethod.POST})
    @ResponseBody
    public  AjaxResult getMarketInfoByTimer(HttpServletRequest request) throws Exception {
        try {
            marketInfoService.getMarketInfoByTimer();
            return AjaxResult.success();
        } catch (Exception e) {
            LOGGER.error("MarketInfoController getMarketInfoByTimer error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

}
